package org.data;

import java.util.Arrays;
import java.util.List;
import java.sql.Timestamp;
import org.h2.jaqu.Table;
import org.util.DateUtil;
import static org.h2.jaqu.Define.*;

/**
 *
 * @author Dmitriy.Krasnov
 */
public class Event implements Table, TableWithId {

    public Integer id;
    public Integer user_id;
    public String name;
    public String place;
    public Timestamp date;
    public Integer deleted; // 1 - true, 0 - false

    public Event() {
        // public constructor
    }

    public Event(Integer id, Integer user_id, String name, String place, Timestamp date) {
        this.id = id;
        this.user_id = user_id;
        this.name = name;
        this.place = place;
        this.date = date;
        this.deleted = 0;
    }

    public void define() {
        tableName("Event");
        primaryKey(id);
    }

    // test
    private static Event create(Integer id, Integer user_id, String name, String place, Timestamp date) {
        return new Event(id, user_id, name, place, date);
    }

    // test method
    public static List<Event> getList() {
        Event[] list = new Event[]{
            create(1, 11, "Event_name1", "Place_name1", new Timestamp(453453)),
            create(2, 21, "Event_name2", "Place_name2", new Timestamp(1543))
        };
        return Arrays.asList(list);
    }

    @Override
    public String toString() {
        return name + " " + date.toString();
    }

    public Integer getId() {
        return id;
    }

    public String getDisplayDate() {
        return null != date ? DateUtil.format(date.getTime(), DateUtil.DATE_AND_TIME_DISPLAY_FORMAT) : "";
    }

    public String getDeleted() {
        return deleted == 0 ? "false" : "true";
    }

    public String getName() {
        return name;
    }

    public String getPlace() {
        return place;
    }

    public String getShowLink() {
        return "<a href=\"showEvent.action?eventId=" + id + "\">EditPic</a> ";
    }

    public String getDeleteLink() {
        return "<a href=\"deleteEventAndlist.action?eventId=" + id + "\">DeletePic</a>";
    }
}